package com.pda.gongpin.ui.fullinventory;


import androidx.recyclerview.widget.RecyclerView;

import com.pda.gongpin.R;
import com.pda.gongpin.adapter.StockAbnormalAdapter;
import com.pda.gongpin.bean.StockAbnormalBean;
import com.pda.gongpin.contract.StockAbnormalContract;
import com.pda.gongpin.presenter.StockAbnormalPresenter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class StockAbnormalFragment extends BaseMvpFragment<StockAbnormalPresenter> implements StockAbnormalContract.View, OnRefreshListener {

    @BindView(R.id.rv_content)
    RecyclerView rvContent;
    @BindView(R.id.smart)
    SmartRefreshLayout smart;
    private String entryNo;
    StockAbnormalAdapter stockAbnormalAdapter;

    public StockAbnormalFragment(String entryNo) {
        this.entryNo = entryNo;
    }

    public StockAbnormalFragment() {
    }

    @Override
    public StockAbnormalPresenter getPresenter() {
        return new StockAbnormalPresenter();
    }


    @Override
    public int getViewId() {
        return R.layout.fragment_list;
    }

    @Override
    public void initView() {
        smart.setEnableLoadMore(false);
        smart.setOnRefreshListener(this);
        stockAbnormalAdapter = new StockAbnormalAdapter(R.layout.item_stock_abnormal, new ArrayList<>());
        rvContent.setAdapter(stockAbnormalAdapter);
        smart.autoRefresh();
    }

    @Override
    public void initLinsenterner() {

    }

    @Override
    public void getData() {

    }

    @Override
    public void showMessage(String msg) {
        super.showMessage(msg);
        smart.finishRefresh();
    }

    @Override
    public void setList(List<StockAbnormalBean> list) {
        stockAbnormalAdapter.setNewInstance(list);
        smart.finishRefresh();
    }

    @Override
    public void onRefresh(RefreshLayout refreshLayout) {
        presenter.stockListOfLoss(entryNo);
    }
}
